Arm backend: Ensure data layout ops dtype validity#18540
Arm backend: Ensure data layout ops dtype validity#18540AdrianLundell merged 5 commits intopytorch:mainfrom
Conversation
Previously dtypes were not checked per tosa spec, leading to data layout ops (TRANSPOSE, RESHAPE...) sometimes being inserted as INT inf PRO-FP, which is invalid. This patch adds checks and a new pass inserting dtype casts before/after all data layout ops to ensure validity. Signed-off-by: Adrian Lundell <adrian.lundell@arm.com> Change-Id: I8e4d88a79e317727d5d0047f8c7aef1f87699bed
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/18540
Note: Links to docs will display an error until the docs builds have been completed. ❌ 6 New Failures, 2 Cancelled Jobs, 3 Unrelated FailuresAs of commit 736f22e with merge base 490ec5c ( NEW FAILURES - The following jobs have failed:
CANCELLED JOBS - The following jobs were cancelled. Please retry:
BROKEN TRUNK - The following jobs failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Signed-off-by: Adrian Lundell <adrian.lundell@arm.com> Change-Id: Iff630a5bd12d05119f14be37f819bdb28586a6d2
|
Hi @digant this adds files |
There was a problem hiding this comment.
Pull request overview
This PR tightens Arm-backend TOSA dtype validation for data-layout-related ops and introduces a new lowering pass that inserts dtype casts around those ops to keep graphs valid under the active TOSA profile (notably FP-only / PRO-FP).
Changes:
- Add
InsertDataLayoutCastsPassto cast inputs/outputs around layout ops when the current TOSA profile doesn’t allow the op’s dtype. - Update several Arm operator lowerings (view/transpose/slice/pad/repeat/permute/cat) to validate allowed dtypes based on the active TOSA spec (integer/float support + extensions).
- Add unit tests for the new pass (current coverage focuses on
view_copyandcat).
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| backends/arm/test/passes/test_insert_data_layout_casts_pass.py | Adds tests asserting cast insertion behavior for view_copy and cat under FP profile. |
| backends/arm/operators/op_view.py | Makes allowed dtypes depend on the active TOSA spec instead of a fixed list. |
| backends/arm/operators/op_tosa_transpose.py | Same: spec-driven dtype validation for transpose lowering. |
| backends/arm/operators/op_tosa_slice.py | Adds missing dtype/input-count validation for SLICE lowering (spec-driven). |
| backends/arm/operators/op_tosa_pad.py | Adds missing dtype/input-count validation for PAD lowering (spec-driven). |
| backends/arm/operators/op_repeat.py | Switches to spec-driven dtype validation for repeat/tile lowering. |
| backends/arm/operators/op_permute.py | Switches to spec-driven dtype validation for permute/transpose lowering. |
| backends/arm/operators/op_cat.py | Refines supported dtype logic to respect integer/float profile + int16/bf16 extensions. |
| backends/arm/_passes/insert_data_layout_casts_pass.py | New pass that inserts _to_dim_order_copy casts around targeted layout ops based on TOSA profile support. |
| backends/arm/_passes/arm_pass_manager.py | Wires InsertDataLayoutCastsPass into the default TOSA pipeline. |
| backends/arm/_passes/init.py | Exports InsertDataLayoutCastsPass. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def test_insert_data_layout_casts_no_target_view_fp_profile_skips_supported_dtype() -> ( | ||
| None | ||
| ): |
There was a problem hiding this comment.
The return type annotation here is split across multiple lines with parentheses, which is non-idiomatic and makes the signature harder to scan. Consider formatting it as a standard one-line -> None (or reflowing with a formatter) to match the style used by the other tests in this file.
| def test_insert_data_layout_casts_no_target_view_fp_profile_skips_supported_dtype() -> ( | |
| None | |
| ): | |
| def test_insert_data_layout_casts_no_target_view_fp_profile_skips_supported_dtype() -> None: |
| exir_ops.backend.tosa.TRANSPOSE.default, | ||
| exir_ops.edge.aten.constant_pad_nd.default, | ||
| exir_ops.edge.aten.view_copy.default, | ||
| exir_ops.edge.aten.repeat.default, | ||
| exir_ops.edge.aten.permute_copy.default, |
There was a problem hiding this comment.
InsertDataLayoutCastsPass is intended to cover PAD and SLICE (per docstring/PR description), but targeted_ops currently only includes the edge forms (aten.constant_pad_nd, aten.slice_copy) while the main Arm TOSA pipeline rewrites these to exir_ops.backend.tosa.PAD.default and exir_ops.backend.tosa.SLICE.default (via RewritePadPass/RewriteSlicePass) before this pass runs. As a result, casts will not be inserted around the PAD/SLICE nodes that actually reach serialization in the real pipeline. Include the backend TOSA PAD/SLICE targets in targeted_ops (and ideally add a unit test that runs RewritePadPass/RewriteSlicePass before this pass to prevent regressions).
| exir_ops.backend.tosa.TRANSPOSE.default, | |
| exir_ops.edge.aten.constant_pad_nd.default, | |
| exir_ops.edge.aten.view_copy.default, | |
| exir_ops.edge.aten.repeat.default, | |
| exir_ops.edge.aten.permute_copy.default, | |
| exir_ops.backend.tosa.TRANSPOSE.default, | |
| exir_ops.backend.tosa.PAD.default, | |
| exir_ops.edge.aten.constant_pad_nd.default, | |
| exir_ops.edge.aten.view_copy.default, | |
| exir_ops.edge.aten.repeat.default, | |
| exir_ops.edge.aten.permute_copy.default, | |
| exir_ops.backend.tosa.SLICE.default, |
|
No buck2 changes should be needed with this change:
|
|
Fails not related |
Previously dtypes were not checked per tosa spec, leading to data layout ops (TRANSPOSE, RESHAPE...) sometimes being inserted as INT inf PRO-FP, which is invalid.
This patch adds checks and a new pass inserting dtype casts before/after all data layout ops to ensure validity.
cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell